#include"processbar.h"
void processbar()
 {
       char a[102];
        char c[4] = "/-\\|";
      memset(a, '\0', sizeof(char) * 102);
       int n = 0;
       while (n <= 100)
       {
           if (n < 100)
           {
               a[n] = '>';
           }
           printf("[%-100s]  [%3d%%] [%c]\r", a, n, c[n % 4]);
           fflush(stdout);
           a[n] = '=';
           n++;
           usleep(1000);
       }
      printf("\n");
}



   char a[103] = { 0 };

 void print(double rate)
 {
       if (rate < 1.0)
          {
             a[0] = '>';
           }
       printf("[%-100s][%.1lf]\r", a, rate);
       fflush(stdout);
       a[(int)rate] = '=';
       if ((int)rate + 1 < 100)
             a[(int)rate + 1] = '>';
    
 }



 void processbar2()
 {
       int  total = filesize;
       double rate = 0.0;
       while (total)
       {
              int one = rand() % (1024 * 1024);
              total -= one;
              if (total < 0)
                {
                    total = 0;
                  }
             usleep(10000);
             int download = filesize - total;
             rate = ((download * 1.0) / (filesize) * 100.0);
              print(rate);
           
       }
        printf("\n");
      
 }

